﻿<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Gramos - Admin Dashboard</title>

    <!-- begin::global styles -->
    <link rel="stylesheet" href="assets/vendors/bundle.css" type="text/css">
    <!-- end::global styles -->

    <!-- begin::custom styles -->
    <link rel="stylesheet" href="assets/css/app.css" type="text/css">
    <!-- end::custom styles -->

</head>
<body class="bg-white h-100-vh p-t-0">

<!-- begin::page loader-->
<div class="page-loader">
    <div class="spinner-border"></div>
    <span>加载中 ...</span>
</div>
<!-- end::page loader -->

<div class="p-b-50 d-block d-lg-none"></div>

<div class="container h-100-vh">
    <div class="row align-items-md-center h-100-vh">
        <div class="col-lg-6 d-none d-lg-block">
            <img class="img-fluid" src="assets/media/svg/register.svg" alt="...">
        </div>
        <div class="col-lg-4 offset-lg-1">

            <!--       注册表单     -->
            <h3>注册</h3>
            <p>创建一个账户<span style="font-weight: bold;color: red" id="error4"></span></p>
            <form id="registerUser">

                <!--       表单主要内容         -->
                <div class="form-group mb-4">
                    <input type="text" name="name" class="form-control form-control-lg" autofocus placeholder="新用户名">
                    <p style="color:red;" id="error1"></p>
                </div>
                <!--<div class="form-group mb-4">
                    <input type="email" class="form-control form-control-lg" placeholder="Email">
                </div>-->
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group mb-4">
                            <input type="password" name="password" class="form-control form-control-lg" placeholder="密码">
                            <p style="color:red;" id="error2"></p>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group mb-4">
                            <input type="password" name="repassword" class="form-control form-control-lg" placeholder="再次确认密码">
                            <p style="color:red;" id="error3"></p>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="custom-control custom-switch">
                        <input type="checkbox" class="custom-control-input" id="customSwitch" checked="">
                        <label class="custom-control-label" for="customSwitch">我同意此规章.</label>
                    </div>
                </div>
                <button type="button" onclick="doRegister()" class="btn btn-primary btn-lg btn-block btn-uppercase mb-4">创建账户</button>
                <!--       表单主要内容         -->

                <p class="text-right">
                    <a href="login" class="text-underline">已有？</a>
                </p>
            </form>
            <!--       注册表单     -->

        </div>
    </div>
</div>
</body>

<!-- begin::global scripts -->
<script src="assets/vendors/bundle.js"></script>
<!-- end::global scripts -->

<!-- begin::custom scripts -->
<script src="assets/js/app.js"></script>
<!-- end::custom scripts -->

<!--开始：注册表单的处理方法-->
<script>
    function doRegister() {
        //1、获取注册表单所需要提交的数据
        var data = new FormData(document.getElementById('registerUser'));
        //2、通过ajax函数提交异步请求 ajax() post() get()
        $.ajax({
            url:'doregister',//请求路径
            type:'post',//请求方式
            data:data,//入参数据

            //对于文件传输设置的属性键值对
            cache:false,//缓存判断
            processData:false,//
            contentType:false,//

            //3、请求成功之后，根据响应的结果来进行操作处理（注册失败/注册成功）
            success:function (result) {//连接成功
                if (result.isok == true) {//注册成功
                    alert(result.message1);
                    location.href = 'login';
                } else {//注册失败
                    if (result.error1 != null) document.getElementById('error1').innerText=result.error1;
                    if (result.error2 != null) document.getElementById('error2').innerText=result.error2;
                    if (result.error3 != null) document.getElementById('error3').innerText=result.error3;
                    if (result.error4 != null) document.getElementById('error4').innerText=result.error4;
                }
            },
            error:function () {//连接失败
                alert("系统繁忙，创建账户失败");
            }
        });

       /* $.post('doRegister', data, function (result) {//result就是data入参后的数据所得到的结果
            //3、请求成功之后，根据响应的结果来进行操作处理（注册失败/注册成功）
            if (result.isok == true) {//注册成功
                alert("成功创建一个账户");
                location.href = 'login';
            } else {//注册失败
                alert(result.errMessage);
            }

        });*/
    }
</script>
<!--结束：注册表单的处理方法-->

</body>
</html>
